package com.ymatou.iapi.trading.userquery.testcase;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.trading.ordersync.service.SyncVerifyService;
import com.ymatou.iapi.trading.userquery.parameter.GetFirstOrderStatusBean;
import com.ymatou.iapi.trading.userquery.service.GetFirstOrderStatusCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.OrderCallService;
import com.ymttest.utils.EnvSetup;
/**
*获取用户首单信息接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetFirstOrderStatus{
	private static GetFirstOrderStatusBean getfirstorderstatusBean;
	private static GetFirstOrderStatusCall getfirstorderstatusCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取用户首单信息接口");
	}

	@Before
	public void caseUp() {
		getfirstorderstatusBean=new GetFirstOrderStatusBean();
		getfirstorderstatusCall=new GetFirstOrderStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getfirstorderstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetFirstOrderStatus_001() {
		Logger.start(true,"获取用户首单信息成功");
		try {		
            OrderCallService orderCallService = new OrderCallService();

            Map user=orderCallService.registerUser();
            Map orderMap=orderCallService.createM2cOrder(user);
        	
            int orderId=(Integer)orderMap.get("orderId");
            int userId=(Integer)user.get("userid");
            
			SyncVerifyService.getSyncResult(orderId);
			          
            List<Integer> buyerIds=new ArrayList<Integer>();
            
            buyerIds.add(userId);
            
            getfirstorderstatusBean.setBuyerIds(buyerIds);
			
			getfirstorderstatusCall.setData(getfirstorderstatusBean);
			getfirstorderstatusCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetFirstOrderStatus_002() {
		Logger.start(true,"确认收货后,获取用户首单信息成功");
		try {		
            OrderCallService orderCallService = new OrderCallService();

            Map user=orderCallService.registerUser();
            Map orderMap=orderCallService.createM2cOrder(user);
            
            int tradingId=(Integer)orderMap.get("tradingId");
            
            int sellerId=(Integer)orderMap.get("sellerId");

            int orderId=(Integer)orderMap.get("orderId");
            int userId=(Integer)user.get("userid");
                 
            // 应付款全金额
            BigDecimal totalPrice = orderCallService.getNeedPrePayAmountOfCashBymainOrderId(tradingId);
            // 支付订单
            orderCallService.orderPayRequest(userId, totalPrice, tradingId);
            
            orderCallService.acceptOrder(orderId, sellerId);
            
            //发货
            orderCallService.dispatched(orderId, sellerId);
    
            //确认收货
            orderCallService.confirmReceive(userId, orderId);
			SyncVerifyService.getSyncResult(orderId);
			          
            List<Integer> buyerIds=new ArrayList<Integer>();
            
            buyerIds.add(userId);
            
            getfirstorderstatusBean.setBuyerIds(buyerIds);
			
			getfirstorderstatusCall.setData(getfirstorderstatusBean);
			getfirstorderstatusCall.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}